
const fs = require('fs')

function registerAllRouters(app) {

  // 1.读取文件夹
  const files = fs.readdirSync(__dirname)

  // 2.读取路由文件
  for (const file of files) {
    if(!file.endsWith('router.js')) continue
    // 导入具体路由对象
    const router = require(`./${file}`)
    // 注册路由
    app.use(router.routes())
    app.use(router.allowedMethods())
  }
}

module.exports = registerAllRouters